package com.example.pachong.service.impl;

import com.example.pachong.pojo.Discuss;
import com.example.pachong.pojo.Ip;
import com.example.pachong.pojo.Users;
import com.example.pachong.pojo.comments;
import com.example.pachong.service.CommentService;
import com.example.pachong.service.DiscussService;
import com.example.pachong.service.IpService;
import com.example.pachong.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CommentServiceImpl implements CommentService {
    @Autowired
    private DiscussService discussService;
    @Autowired
    private IpService ipService;
    @Autowired
    private UserService userService;

    @Override
    public void tianjia(comments comment) {
        Users users = new Users();
        users.setUid(comment.getUser().getUid());
        users.setNickname(comment.getUser().getNickname());
        users.setLevel(Integer.parseInt(comment.getUser().getLevelexp().getLevel()));
        users.setFreq(0);
        users.setTemp(0);
        users.setShorttemp(0);
        users.setFinallytime(comment.getReply().getCreatedat());
        userService.tianjia(users);

        Ip ip = new Ip();
        ip.setIdip(comment.getUser().getUid());
        ip.setIpcol(comment.getUser().getIpRegion());
        ip.setIpfreq(0);
        ipService.tianjia(ip);

        Discuss discuss = new Discuss();
        discuss.setIddis(comment.getReply().getUid());
        discuss.setDiscusscol(comment.getReply().getContent());
        discuss.setTime(comment.getReply().getCreatedat());
        discuss.setDisfreq(0);
        discuss.setTemp(0);
        discussService.tianjia(discuss);
    }
}
